import CryptoJS from 'crypto-js/crypto-js';
// 加密
export const encrypt = (word) => {
  console.log(word);
  const key = CryptoJS.enc.Utf8.parse('46cc793c53dc451b');
  const srcs = CryptoJS.enc.Utf8.parse(word);
  const iv = CryptoJS.enc.Utf8.parse('abcdefgabcdefg12');
  const encrypted = CryptoJS.AES.encrypt(srcs, key, {
    iv,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7,
  });
  console.log(encrypted.toString());
  return encrypted.toString();
};
// 解密
export const decrypt = (data) => {
  console.log(data);
  const key = CryptoJS.enc.Utf8.parse('46cc793c53dc451b');
  const iv = CryptoJS.enc.Utf8.parse('abcdefgabcdefg12');
  const decrypt = CryptoJS.AES.decrypt(data, key, {
    iv,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7,
  });
  console.log(CryptoJS.enc.Utf8.stringify(decrypt).toString());
  return CryptoJS.enc.Utf8.stringify(decrypt).toString();
};
